//
//  MainViewController.swift
//  SinaWeiboDemo
//
//  Created by 伍禄林 on 16/9/20.
//  Copyright © 2016年 伍禄林. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let mianTabBar = MainTabBar()
        
        setValue(mianTabBar, forKey: "tabBar")
        addChildViewControllers()
        
        mianTabBar.compseBtn.addTarget(self, action: #selector(MainViewController.composeDidClick), for: UIControlEvents.touchUpInside)
        
    }
    
    @objc private func composeDidClick() {
        
        print("composeDidClick========")
    }
    
    private func addChildViewControllers() {
        
        addChildViewController(vc: HomeTableViewController(),title: "首页",imageNamed: "tabbar_home")
        addChildViewController(vc: MessageTableViewController(),title: "消息",imageNamed: "tabbar_message_center")
        addChildViewController(vc: DiscoverTableViewController(),title: "发现",imageNamed: "tabbar_discover")
        addChildViewController(vc: ProfileTableViewController(),title: "我",imageNamed: "tabbar_profile")
    }
    
    
    private func addChildViewController(vc: UIViewController, title: String, imageNamed: String) {
        
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageNamed)
        
//        vc.tabBarItem.selectedImage = UIImage(named: imageNamed + "_highlighted")
//        
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        
        addChildViewController(nav)
        
    }
}
